package com.mtk.launcher.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.mtk.launcher.R;

import java.util.ArrayList;
import java.util.HashMap;

public class SettingsAdapter extends BaseAdapter {

    private Context context;
    private ArrayList<HashMap<String, String>> settingsList;

    public SettingsAdapter(Context context, ArrayList<HashMap<String, String>> settingsList) {
        this.context = context;
        this.settingsList = settingsList;
    }

    @Override
    public int getCount() {
        return settingsList.size();
    }

    @Override
    public Object getItem(int position) {
        return settingsList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.list_item_setting, parent, false);
        }

        ImageView icon = convertView.findViewById(R.id.icon);
        TextView title = convertView.findViewById(R.id.title);
        TextView subtitle = convertView.findViewById(R.id.subtitle);

        HashMap<String, String> setting = settingsList.get(position);
        icon.setImageResource(Integer.parseInt(setting.get("icon")));
        title.setText(setting.get("title"));
        subtitle.setText(setting.get("subtitle"));

        return convertView;
    }
}
